﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GMS.MainClasses;
using GMS.MainForm;
using GMS.ServiceFunctions.FunctionForControls;
using GMS.ServiceFunctions.Data;

namespace GMS.ViewForms
{
    public partial class ViewForms : ChildForms
    {
        FunctionsForDataGridView FFDGV = new FunctionsForDataGridView();
        BindingSource bsFroms = new BindingSource();
        public ViewForms( )
        {
            InitializeComponent();

            StoredProcedures = new String[1];
            StoredProcedures[0] = "[SelectForms]";
        }

        private void ViewForms_Load(object sender, EventArgs e)
        {
            bsFroms.DataSource = MRF.ReturnDataSetDB(ConnectionString, StoredProcedures[0]);
            bsFroms.DataMember = "table";

            dataGridView1.DataSource = bsFroms;
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            bsFroms.Filter = "[Название формы] like '%" + textBox1.Text.Trim() + "%'";
        }

        private void textBox2_KeyUp(object sender, KeyEventArgs e)
        {
            bsFroms.Filter = "[Сборка] like '%" + textBox2.Text.Trim() + "%'";
        }

        private void textBox3_KeyUp(object sender, KeyEventArgs e)
        {
            bsFroms.Filter = "[Пространство имен] like '%" + textBox3.Text.Trim() + "%'";
        }

        private void AddFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEditForm AEF = new AddEditForm(AddEditForm.EditMode.Добавление);
            AEF.ConnectionString = ConnectionString;
            AEF.MdiParent = MRF;
            AEF.Show();
        }

        private void EditFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEditForm AEF = new AddEditForm(AddEditForm.EditMode.Редактирование);
            AEF.ConnectionString = ConnectionString;
            AEF.IdForm = Convert.ToInt32(dataGridView1.CurrentRow.Cells["IdForm"].Value);
            AEF.MdiParent = MRF;
            AEF.Show();
        }

        private void DeleteFormToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddEditForm AEF = new AddEditForm(AddEditForm.EditMode.Удаление);
            AEF.ConnectionString = ConnectionString;
            AEF.IdForm = Convert.ToInt32(dataGridView1.CurrentRow.Cells["IdForm"].Value);
            AEF.MdiParent = MRF;
            AEF.Show();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            AddFormToolStripMenuItem_Click(sender, e);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            EditFormToolStripMenuItem_Click(sender, e);
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            DeleteFormToolStripMenuItem_Click(sender, e);
        }

        private void ViewForms_Activated(object sender, EventArgs e)
        {
            bsFroms.DataSource = MRF.ReturnDataSetDB(ConnectionString, StoredProcedures[0]);
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            AboutForms AF = new AboutForms();
            AF.Show();
        }
    }
}
